package io.kimmking.dubbo.demo.consumer.controller;

import io.kimmking.dubbo.demo.consumer.response.BaseResponse;
import io.kimmking.dubbo.demo.consumer.service.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @author gechenpeng
 * @date 2021-06-07
 */
@Api(tags = "账户")
@Slf4j
@RestController
@RequestMapping("/account")
public class AccountController {

    private final AccountService accountService;

    @Autowired(required = false)
    public AccountController(AccountService accountService) {
        this.accountService = accountService;
    }

    @ApiOperation("兑换人民币")
    @PostMapping("/exchange-for-rmb")
    public BaseResponse exchangeForRmb(@RequestParam(value = "userId", required = false) String userId,
                                       @RequestParam(value = "dollarAmount", required = false) BigDecimal dollarAmount) {
        accountService.exchangeForRmb(userId, dollarAmount);
        return BaseResponse.ok();
    }
}
